package com.huawei.esdk.tp.device.smc.v100r003c10;

import java.util.Date;
import java.util.List;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.common.exception.SDKException;
import com.huawei.esdk.platform.common.utils.DateUtils;
import com.huawei.esdk.platform.commu.itf.ICXFSOAPProtocolAdapter;
import com.huawei.esdk.platform.exception.ProtocolAdapterException;
import com.huawei.esdk.tp.device.smc.v100r003c00.SMC20V1R3C00ConferenceManagerCapabilityImpl;
import com.huawei.esdk.tp.device.smc.v100r003c10.convert.TPSMC20V1R3C10ConfMgrConvert;
import com.huawei.esdk.tp.domain.model.PeriodicalConference;
import com.huawei.esdk.tp.domain.model.ScheduleConference;
import com.huawei.esdk.tp.domain.model.bean.AdhocConfFreeBusyStateList;
import com.huawei.esdk.tp.domain.model.bean.AdhocConferencesList;
import com.huawei.esdk.tp.domain.model.bean.ContinuousPresenceParam;
import com.huawei.esdk.tp.domain.model.bean.PointToPointCDRQueryConfig;
import com.huawei.esdk.tp.domain.model.bean.QuerySites;
import com.huawei.esdk.tp.domain.model.bean.MultiPointCDRQueryConfig;
import com.huawei.esdk.tp.domain.model.bean.MultiPointCDRResult;
import com.huawei.esdk.tp.domain.model.bean.PagedList;
import com.huawei.esdk.tp.domain.model.bean.PointToPointCDR;
import com.huawei.esdk.tp.domain.model.bean.SiteMCU;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.ArrayOfString;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.ConferenceId;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.EditFutureConf;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.EditFutureConfResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.GetContinuousPresenceParam;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.GetContinuousPresenceParamResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryAdhocConfFreeBusy;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryAdhocConfFreeBusyResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryAdhocConferences;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryAdhocConferencesResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryConfSiteMcu;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryConfSiteMcuResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryMultiPointCDR;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryMultiPointCDRResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryPointToPointCDR;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.QueryPointToPointCDRResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.ScheduleConf;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.ScheduleConfResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.SmcExternal2Soap;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.SynchAdhocConfFreeBusy;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c10.SynchAdhocConfFreeBusyResponse;

public class SMC20V1R3C10ConferenceManagerCapabilityImpl extends SMC20V1R3C00ConferenceManagerCapabilityImpl implements
    SMC20V1R3C10IConferenceManagerCapability
{
    private TPSMC20V1R3C10ConfMgrConvert tpConfMgrConvertService = new TPSMC20V1R3C10ConfMgrConvert();
    
    /** * @param cxfSoapProtocolAdapter */
    public SMC20V1R3C10ConferenceManagerCapabilityImpl(ICXFSOAPProtocolAdapter cxfSOAPProtocolAdapter)
    {
        super(cxfSOAPProtocolAdapter);
    }
    
    protected String getR3C10SouthItfName()
    {
        return SmcExternal2Soap.class.getName();
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public SDKResult<ScheduleConference> scheduleConference(ScheduleConference conf)
    {
        
        SDKResult<ScheduleConference> result = new SDKResult<ScheduleConference>();
        ScheduleConfResponse responseSouth = null;
        try
        {
            ScheduleConf resMsg = tpConfMgrConvertService.scheduleConfModel2soap(conf);
            
            responseSouth = (ScheduleConfResponse)sendProtocolMessage(resMsg, getR3C10SouthItfName(), "scheduleConf");
            result = (SDKResult<ScheduleConference>)tpConfMgrConvertService.scheduleConfSoap2model(responseSouth);
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        catch (SDKException e)
        {
            result.setErrCode(e.getSdkErrCode());
            return result;
        }
        
        return result;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public SDKResult<PeriodicalConference> scheduleRecurrenceConference(PeriodicalConference conf)
    {
        SDKResult<PeriodicalConference> result = new SDKResult<PeriodicalConference>();
        ScheduleConfResponse responseSouth = null;
        try
        {
            ScheduleConf resMsg = tpConfMgrConvertService.scheduleConfModel2soap(conf);
            
            responseSouth = (ScheduleConfResponse)sendProtocolMessage(resMsg, getR3C10SouthItfName(), "scheduleConf");
            result = (SDKResult<PeriodicalConference>)tpConfMgrConvertService.scheduleConfSoap2model(responseSouth);
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        catch (SDKException e)
        {
            result.setErrCode(e.getSdkErrCode());
            return result;
        }
        
        return result;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public SDKResult<ScheduleConference> editScheduleConference(ScheduleConference conf)
    {
        SDKResult<ScheduleConference> result = new SDKResult<ScheduleConference>();
        EditFutureConfResponse responseSouth = null;
        try
        {
            EditFutureConf resMsg = tpConfMgrConvertService.editScheduleConfModel2soap(conf);
            
            responseSouth =
                (EditFutureConfResponse)sendProtocolMessage(resMsg, getR3C10SouthItfName(), "editFutureConf");
            result = (SDKResult<ScheduleConference>)tpConfMgrConvertService.editScheduleConfSoap2model(responseSouth);
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        catch (SDKException e)
        {
            result.setErrCode(e.getSdkErrCode());
            return result;
        }
        
        return result;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public SDKResult<PeriodicalConference> editScheduleRecurrenceConference(PeriodicalConference conf)
    {
        SDKResult<PeriodicalConference> result = new SDKResult<PeriodicalConference>();
        EditFutureConfResponse responseSouth = null;
        try
        {
            EditFutureConf resMsg = tpConfMgrConvertService.editScheduleConfModel2soap(conf);
            
            responseSouth =
                (EditFutureConfResponse)sendProtocolMessage(resMsg, getR3C10SouthItfName(), "editFutureConf");
            result = (SDKResult<PeriodicalConference>)tpConfMgrConvertService.editScheduleConfSoap2model(responseSouth);
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        catch (SDKException e)
        {
            result.setErrCode(e.getSdkErrCode());
            return result;
        }
        
        return result;
    }
    
    @Override
    public SDKResult<AdhocConfFreeBusyStateList> queryAdhocConfFreeBusyEx(Integer duration, Date beginTime,
        List<String> confAccessCodes)
    {
        SDKResult<AdhocConfFreeBusyStateList> result = new SDKResult<AdhocConfFreeBusyStateList>();
        QueryAdhocConfFreeBusyResponse response = null;
        
        // 调用接口前转换
        QueryAdhocConfFreeBusy resMsg =
            tpConfMgrConvertService.queryAdhocConfFreeBusyModel2Soap(duration, beginTime, confAccessCodes);
        
        try
        {
            response =
                (QueryAdhocConfFreeBusyResponse)sendProtocolMessage(resMsg,
                    getR3C10SouthItfName(),
                    "queryAdhocConfFreeBusy");
            
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        // 南向转换成领域
        result = tpConfMgrConvertService.queryAdhocConfFreeBusySoap2Model(response);
        
        return result;
    }
    
    @Override
    public SDKResult<AdhocConfFreeBusyStateList> synchAdhocConfFreeBusyEx(Integer duration, Date beginTime,
        List<String> confAccessCodes)
    {
        SDKResult<AdhocConfFreeBusyStateList> result = new SDKResult<AdhocConfFreeBusyStateList>();
        SynchAdhocConfFreeBusyResponse response = null;
        
        // 调用接口前转换
        SynchAdhocConfFreeBusy resMsg =
            tpConfMgrConvertService.synchAdhocConfFreeBusyModel2Soap(duration, beginTime, confAccessCodes);
        
        try
        {
            response =
                (SynchAdhocConfFreeBusyResponse)sendProtocolMessage(resMsg,
                    getR3C10SouthItfName(),
                    "synchAdhocConfFreeBusy");
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        // 南向转换成领域
        result = tpConfMgrConvertService.synchAdhocConfFreeBusySoap2Model(response);
        
        return result;
    }
    
    @Override
    public SDKResult<AdhocConferencesList> queryAdhocConferencesEx(QuerySites querySites)
    {
        SDKResult<AdhocConferencesList> result = new SDKResult<AdhocConferencesList>();
        QueryAdhocConferencesResponse response = null;
        
        // 调用接口前转换
        QueryAdhocConferences resMsg = tpConfMgrConvertService.queryAdhocConferencesModel2Soap(querySites);
        
        try
        {
            response =
                (QueryAdhocConferencesResponse)sendProtocolMessage(resMsg,
                    getR3C10SouthItfName(),
                    "queryAdhocConferences");
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        // 南向转换成领域
        result = tpConfMgrConvertService.queryAdhocConferencesSoap2Model(response);
        
        return result;
    }
    
    @Override
    public SDKResult<PagedList<PointToPointCDR>> queryPointToPointCDR(PointToPointCDRQueryConfig queryConfig)
    {
        SDKResult<PagedList<PointToPointCDR>> result = new SDKResult<PagedList<PointToPointCDR>>();
        QueryPointToPointCDRResponse response = null;

        try
        {
            QueryPointToPointCDR request = tpConfMgrConvertService.queryPointToPointCDRModal2Soap(queryConfig);
            
            response =
                (QueryPointToPointCDRResponse)sendProtocolMessage(request,
                    getR3C10SouthItfName(), "queryPointToPointCDR");
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        catch (SDKException e)
        {
            result.setErrCode(e.getSdkErrCode());
            return result;
        }
        
        // 南向转换成领域
        result = tpConfMgrConvertService.queryPointToPointCDRSoap2Model(response);
        
        return result;
    }
    
    @Override
    public SDKResult<MultiPointCDRResult> queryMultiPointCDREx(MultiPointCDRQueryConfig queryConfig)
    {
        SDKResult<MultiPointCDRResult> result = null;
        QueryMultiPointCDRResponse response = null;
        
        QueryMultiPointCDR resMsg = tpConfMgrConvertService.queryMultiPointCDRExModel2Soap(queryConfig);
        
        try
        {
            response =
                (QueryMultiPointCDRResponse)sendProtocolMessage(resMsg,
                    getR3C10SouthItfName(), "queryMultiPointCDR");
        }
        catch (ProtocolAdapterException e)
        {
            result = new SDKResult<MultiPointCDRResult>();
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        result = tpConfMgrConvertService.queryMultiPointCDRExSoap2Model(response);
        return result;
    }
    
    @Override
    public SDKResult<ContinuousPresenceParam> getContinuousPresenceParamEx(String confId, String target)
    {
        SDKResult<ContinuousPresenceParam> result = new SDKResult<ContinuousPresenceParam>();
        GetContinuousPresenceParamResponse response = null;
        
        GetContinuousPresenceParam resMsg = new GetContinuousPresenceParam();
        ConferenceId conferenceId = new ConferenceId();
        conferenceId.setConfInternalId(Long.parseLong(confId));
        resMsg.setConfId(conferenceId);
        resMsg.setTarget(target);
        
        try
        {
            response =
                (GetContinuousPresenceParamResponse)sendProtocolMessage(resMsg,
                    getR3C10SouthItfName(),
                    "getContinuousPresenceParam");
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        result = tpConfMgrConvertService.getContinuousPresenceParamExSoap2Model(response);
        
        return result;
    }
    
    @Override
    public SDKResult<List<SiteMCU>> queryConfSiteMCU(String confId, List<String> siteUris, Date date)
    {
        SDKResult<List<SiteMCU>> result = new SDKResult<List<SiteMCU>>();
        QueryConfSiteMcuResponse response = null;
        
        // 调用接口前转换
        QueryConfSiteMcu resMsg = new QueryConfSiteMcu();
        ConferenceId conferenceId = new ConferenceId();
        conferenceId.setConfInternalId(Long.parseLong(confId));
        resMsg.setConfId(conferenceId);
        
        resMsg.setBeginTime(DateUtils.setTimezoneToUTC(DateUtils.toGregorianCalendarDate(date), 0));
        
        if (null != siteUris)
        {
            ArrayOfString strArray = new ArrayOfString();
            for (String str : siteUris)
            {
                strArray.getString().add(str);
            }
            resMsg.setSiteUris(strArray);
        }
        
        try
        {
            response =
                (QueryConfSiteMcuResponse)sendProtocolMessage(resMsg,
                    getR3C10SouthItfName(), "queryConfSiteMcu");
        }
        catch (ProtocolAdapterException e)
        {
            result.setErrCode(e.getErrorCode());
            return result;
        }
        
        // 南向转换成领域
        result = tpConfMgrConvertService.queryConfSiteMcuSoap2Model(response);
        
        return result;
    }
}
